<?php

namespace app\common\util;

use think\facade\Log;

/**
 * 封装thinkphp的日志
 */
class TpLog extends SingleObjectClass
{
    protected $chennel = 'file';//日志通道

    /**
     * 设置通道
     * @param $chennel
     * @return void
     */
    public function setChennel($chennel)
    {
        $this->chennel = $chennel;
    }

    public function __construct()
    {

    }

    /**
     * 记录日志
     * @param $log
     * @param $type
     * @param bool $doubleWrite 是否写到tp日志，为true就是写多一份到tp日志
     * @return
     * @return \think\log\Channel|\think\log\ChannelSet
     */
    public function record($log, $type = "info", $doubleWrite = false)
    {
        if ($doubleWrite) {
            Log::record($log, $type);
        }
        return Log::channel($this->chennel)->record($log, $type);
    }

    public function write($log, $type = "info")
    {
        return Log::channel($this->chennel)->write($log, $type);
    }

    public function debug($log, $type = "debug")
    {
        return Log::channel($this->chennel)->debug($log);
    }

    public function info($log, $type = "info")
    {
        return Log::channel($this->chennel)->info($log);
    }

    public function warning($log, $type = "warning")
    {
        return Log::channel($this->chennel)->warning($log);
    }

    public function error($log, $type = "error")
    {
        return Log::channel($this->chennel)->error($log);
    }

    public function critical($log, $type = "critical")
    {
        return Log::channel($this->chennel)->critical($log);
    }


}